package com.gary;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.write.*;

import java.io.File;
import java.io.IOException;

/**
 * @author pengrui3
 * @date 2020/11/23-20:38
 */
public class TransferExcel {
    public static void main(String[] args) throws IOException, WriteException {

        WritableWorkbook writableWorkbook = null;
        try {
            //创建工作簿
            writableWorkbook = Workbook.createWorkbook(new File("E:/workDoc/statistics/test.xls"));
            //创建工作表
            WritableSheet testSheet = writableWorkbook.createSheet("testSheet", 0);
            //合并单元格
            //表头
            testSheet.mergeCells(0, 0, 15, 0);
            WritableCellFormat titleFormat = new WritableCellFormat();
            titleFormat.setAlignment(Alignment.CENTRE);
            WritableFont writableFont = new WritableFont(WritableFont.createFont("黑体"), 20);
            titleFormat.setFont(writableFont);
            testSheet.addCell(new Label(0,0,"采集工作完成情况统计表(省市级)", titleFormat));
            //说明部分
            testSheet.mergeCells(0, 1, 4, 1);
            testSheet.mergeCells(5,1,15,1);
            writableFont = new WritableFont(WritableFont.createFont("楷体"), 14);
            WritableCellFormat discFormat = new WritableCellFormat();
            discFormat.setAlignment(Alignment.LEFT);
            discFormat.setFont(writableFont);
            testSheet.addCell(new Label(0,1,"单位：xxx市", discFormat));
            testSheet.addCell(new Label(5,1,"统计时间：2020年11月24日", discFormat));
            writableWorkbook.write();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            writableWorkbook.close();
        }
    }
}
